<?php
defined( 'BASEPATH' ) or exit( 'No direct script access allowed' );
class User_permission_model extends MY_Model
{
    function check($role_id, $uri)
    {
        $this->_db->select( $this->_table, '`id`' );
        $this->_db->where( '`role_id`=? and `uri`=? and `flag`=1', array (
                $role_id,
                $uri 
        ) );
        return $this->_db->fetch_row();
    }
    function uris($role_id, $uri_type = 0)
    {
        $this->_db->select( $this->_table, '`uri`' );
        $this->_db->where( '`role_id`=? and `uri_type`=? and `flag`=1', array (
                $role_id,
                $uri_type 
        ) );
        return $this->_db->fetch_all();
    }
    function exist($role_id, $uri)
    {
        $this->_db->select( $this->_table, '`id`' );
        $this->_db->where( '`role_id`=? and `uri`=?', array (
                $role_id,
                $uri 
        ) );
        return $this->_db->fetch_row();
    }
    function set($role_id, $uri, $flag)
    {
        $this->_db->update( $this->_table, array (
                'flag' => empty( $flag ) ? 0 : 1 
        ) );
        $this->_db->where( '`role_id`=? and `uri`=?', array (
                $role_id,
                $uri 
        ) );
        return $this->_db->affected_rows();
    }
}